package com.example.cookbook.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.cookbook.R;
import com.example.cookbook.bean.StepsBean;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;

public class StepAdapter extends RecyclerView.Adapter<StepAdapter.ViewHolder>  {
    private List<StepsBean> mStepList;
    private Context homecontext;
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView i_imageurlstep;
        TextView i_ordernumstep,i_contentstep;
        public ViewHolder(View view){
            super(view);
            i_imageurlstep = view.findViewById(R.id.i_imageurlstep);
            i_ordernumstep = view.findViewById(R.id.i_ordernumstep);
            i_contentstep = view.findViewById(R.id.i_contentstep);
        }
    }
    //构造函数
    public StepAdapter(Context context, List<StepsBean> StepList){
        mStepList = StepList;
        homecontext = context;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.recy_item_step,parent,false);
        ViewHolder holder=new ViewHolder(view);
        return holder;
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        StepsBean  stepsBean = mStepList.get(position);
        //这里选用了Glide框架，其中load()中传入的为图片地址，into()中表明将图片指向哪个ImageView
        Glide.with(homecontext).load(stepsBean.getImgUrl()).into(holder.i_imageurlstep);
        holder.i_ordernumstep.setText("第"+stepsBean.getOrderNum()+"步");
        holder.i_contentstep.setText(stepsBean.getContent());
    }
    @Override
    public int getItemCount() {
        return mStepList.size();
    }

}